home *** CD-ROM | disk | FTP | other *** search
/ EDUCORP 8 / Educorp2Compilation.sit / educorp2 / Fonts (2800) / 2830 Display Fonts / Font Tools / FontLister / fontList.c < prev    next >
C/C++ Source or Header  |  1987-12-30  |  3KB  |  163 lines

  1. /* Font Lister Desk Accessory. Version 1.0 Dec 30/87     */
  2. /* by Jim Leitch Toronto  CIS 70416,1532                */
  3.  
  4. #include     <DeviceMgr.h>
  5. #include    <EventMgr.h>
  6. #include    <WindowMgr.h>
  7. #include    <FontMgr.h>
  8.  
  9. #define DAopen        0
  10. #define DAcontrol    2
  11. #define DAclose        4
  12.  
  13. typedef EventRecord    **EventHandle;
  14.  
  15. Boolean    already_open = false;
  16. DCtlPtr    dce;
  17. Rect windowRect;
  18. EventRecord myEvent;
  19.  
  20. main(p,d,n)
  21. cntrlParam *p;
  22. DCtlPtr d;
  23. int n;
  24. {    if(!d->dCtlStorage) 
  25.     {    if (n == DAopen)
  26.         {    SysBeep(10);    
  27.             CloseDriver(d->dCtlRefNum);
  28.         }
  29.         return (noErr);
  30.     }
  31.     dce = d;
  32.     switch (n) 
  33.     {    case DAopen:
  34.             doOpen();
  35.             break;
  36.         case DAcontrol:
  37.             doControl(p, d);
  38.             break;
  39.         case DAclose:
  40.             DisposeWindow(dce->dCtlWindow);
  41.             break;
  42.         default:
  43.             break;
  44.     }
  45.     return(noErr);
  46. }
  47.  
  48. doOpen()
  49. {    int fNum,numFonts = 0,winBottom,winRight;
  50.     char str[32];
  51.     dce->dCtlFlags |= dNeedLock;
  52.     if (already_open)
  53.         return;
  54.     for(fNum = 0; fNum <= 512; fNum++)    /* scan to determine window size */
  55.     {    GetFontName(fNum,str);
  56.         if(StringWidth(str) > 0)
  57.             numFonts++;
  58.     }
  59.     winRight = numFonts > 21 ? 500 : 260;
  60.     winBottom = numFonts > 21 ? 332 : numFonts * 12 + 76;
  61.     already_open = true;
  62.     SetRect(&windowRect,8,40,winRight,winBottom);
  63.     dce->dCtlWindow =
  64.         NewWindow(0L,&windowRect,"\pAvailable Fonts",true,16,-1L,true,0L);
  65.     ((WindowPeek)dce->dCtlWindow)->windowKind = dce->dCtlRefNum;
  66.     SetPort(dce->dCtlWindow);
  67. }
  68.  
  69. doControl(p, d)
  70. cntrlParam *p;
  71. DCtlPtr d;
  72. {    Point mousePt;
  73.     char ch;
  74.     switch (p->csCode) 
  75.     {    case accEvent:
  76.             myEvent = **(EventHandle)p->csParam;            
  77.             SetPort(dce->dCtlWindow);     
  78.             switch (myEvent.what) 
  79.             {    case activateEvt:
  80.                     doActivate(myEvent.message);
  81.                     break;
  82.                 case updateEvt:
  83.                     doUpdate(myEvent.message);
  84.                     break;
  85.                 default:
  86.                     break;
  87.             }
  88.             break;
  89.         default:
  90.             break;
  91.     }
  92. }
  93.  
  94. doActivate(convWin)
  95. WindowPtr convWin;
  96. {    GrafPtr oldPort;
  97.     GetPort(&oldPort);
  98.     SetPort(convWin);
  99.     SetPort(oldPort);
  100. }
  101.  
  102. doUpdate(convWin)
  103. WindowPtr convWin;
  104. {    GrafPtr oldPort;
  105.     GetPort(&oldPort);
  106.     SetPort(convWin);
  107.     BeginUpdate(convWin);
  108.         decribeFonts();    
  109.     EndUpdate(convWin);
  110.     SetPort(oldPort);
  111. }
  112.  
  113. decribeFonts()    
  114. {     int fNum,fSize,h = 2,v = 22,tab,totalFonts = 0,totalSizes = 0;
  115.     Str255 str;
  116.     TextFont(1);
  117.     TextSize(9);
  118.     for(fNum = 0; fNum <= 512; fNum++)
  119.     {    GetFontName(fNum,str);
  120.         if(StringWidth(str) > 0)
  121.         {    if(v == 22 )
  122.             {    MoveTo(h,10);
  123.                 DrawString("\pNumber    Name                Sizes");
  124.             }
  125.             writeValue(h,v,fNum);
  126.             MoveTo(h + 33,v);
  127.             DrawString(str);
  128.             tab = h + 90;
  129.             for(fSize = 7; fSize <= 48; fSize++)
  130.                 if(RealFont(fNum,fSize))
  131.                 {    writeValue(tab+=15,v,fSize);
  132.                     totalSizes++;
  133.                 }
  134.             v += 12;
  135.             totalFonts++;
  136.             if(v > 295)
  137.             {    v = 22;
  138.                 h += 250;
  139.             }
  140.         }
  141.     }
  142.     v += 11;
  143.     if(v > 295)
  144.     {    v = 26;
  145.         h += 250;
  146.     }
  147.     writeValue(h + 30,v,totalFonts);
  148.     DrawString("\p Fonts");
  149.     writeValue(h + 105,v,totalSizes);
  150.     DrawString("\p Sizes");
  151. }
  152.  
  153. writeValue(h,v,val)
  154. int h,v,val;
  155. {    char strg[10];
  156.     NumToString((long)val,strg);
  157.     h = val < 10 ? h = h + 6 : h;
  158.     h = val < 100 ? h = h + 6 : h;
  159.     MoveTo(h,v);
  160.     DrawString(strg);
  161. }    
  162.  
  163.